<%@page import="com.wanmait.movies.vo.Pager"%>
<%@page import="com.wanmait.movies.vo.Discuss"%>
<%@page import="java.text.DecimalFormat"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="com.wanmait.movies.vo.Actor"%>
<%@page import="com.wanmait.movies.vo.Director"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.wanmait.movies.vo.Movie"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<script src="/movies/js/jquery-3.5.1.min.js" type="text/javascript"></script>
	
	<jsp:include page="/include/head.jsp"></jsp:include>
	<jsp:include page="/include/neck.jsp"></jsp:include>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<%Movie movie =(Movie)request.getAttribute("movie"); %>
<%ArrayList<Director> allDirector=(ArrayList<Director>)request.getAttribute("allDirector"); %>
<%ArrayList<Actor> allActor=(ArrayList<Actor>)request.getAttribute("allActor"); %>
<%ArrayList<Discuss> allDiscuss=(ArrayList<Discuss>)request.getAttribute("allDiscuss"); %>
<%Pager pager=(Pager)request.getAttribute("pager");%>
<%double fenshu=(double)request.getAttribute("fenshu");
	DecimalFormat df = new DecimalFormat("#.0");
	String str = df.format(fenshu);
%>
<style type="text/css">
	body{
	background-color:#f5f5f5;
	}
.div .listdiv,.pinlundiv,.showpinglun div{
	background-color:#FFFFFF;
}
.listdiv{
	width:900px;
	margin: -9px auto  ;
	height:530px;
	margin-top: -15px;
}
.pinlundiv{
	width:900px;
	height:320px;
	margin: auto  ;
}
.showpinglun{
	width:900px;
	margin: auto;
}
.imgdiv{
	
	width:300px;
	float: left;
}
.haibao{
	margin-left:10px;
	margin-top:50px;
	width:300px;
	height:420px;
	background-size: 100% 100%;
	
}

.jianjiediv{
	
	width:300px;
	height:200px;
	float: left;
	margin-left: 0px;
	
}
a{
	text-decoration: none;
	color:black;
}
.moviename{
	font-size: 40px;
}
.dianzan{
	width:150px;
}
.xingxing{
	width:20px;
}

.shoucang{
	width:20px;
	
}
.dafendiv{
	margin-left: 10px;
	height:300px;
	float: left;
}

 ul{
	list-style: none;
}
.dafendiv li{
	text-align: center;
}
.shoucangli{ 
	margin-bottom: 1px;
}
.fenshutext{
	margin-top:10px;
	margin-left:10px;
	background-color: red;
	border-radius:50px;
	height:55px;
	width:55px;
	font-size:30px;
	border:0px solid red;
	text-align: center;
}
.tijiao{
	margin-left: 800px;
	background-color: red;
	width:100px; 
	height:40px;
}
.shuru{
	font-size:40px;
}  
.touxiang{
	width:30px;
	height:30px;
}

.beipinglundiv{
	width:600px;
	margin-left: 34px;
}
	
</style>
</head>

<script src="/movies/ueditor/ueditor.config.js" type="text/javascript"></script>
<script src="/movies/ueditor/ueditor.all.min.js" type="text/javascript"></script>
<script type="text/javascript">
var ediu;
var item={initiaFrameHeight:600,autoFloatEnabled:false,autoHeightEnabled:false};
$(function(){
	ediu=UE.getEditor("pinglun",item);
	
	
})

//网页加载结束后添加电影照片
$(function(){
	
	$(".haibao").css("background-image","url=/movies/images/<%=movie.getMovieImage()%>");
})
//网页加载结束后给打分的星星添加点击方法
$(function(){
	$(".xingxing").click(xxx);
})
//打分星星的点击方法
function xxx(){
		var a=parseInt($(this).attr("value"));
		var str="";
		$(".xingxingli").html(str);
		$.ajax({
			url:"/movies/MoviesServlet?",
			type:"get",
			data:{action:"dafen",fenshu:a,movieId:"<%=movie.getId()%>"},
			async:false,
			success:function(mes){
				if(mes=="0"){
					location.href="/movies/denglupage.jsp";
				}
				else{
					var a=parseFloat(mes);
					a=a.toFixed(1);
					$(".fenshutext").val(a);
				}
				
			}
		})
		for(var i=1;i<=a;i++){
			var aaaa=$("<img>");
			aaaa.attr("src","<%=request.getContextPath()%>/images/星星4.png");
			aaaa.attr("value",i);
			aaaa.addClass("xingxing");
			aaaa.click(xxx);
			$(".xingxingli").append(aaaa);
		}
		for(var j=a+1;j<=5;j++){
			var aaaa=$("<img>");
			aaaa.attr("src","<%=request.getContextPath()%>/images/星星3.png");
			aaaa.attr("value",j);
			aaaa.addClass("xingxing");
			aaaa.click(xxx);
			$(".xingxingli").append(aaaa);
		}
		
	}
	
	//网页加载结束后给点赞添加方法
	$(function(){
		$(".dianzan").click(dianzana);
	})
	
	//点赞的方法
	function dianzana(){
		var a=parseInt($(this).attr("value"));
		if(a==0){
			$(".dianzanli").html("");
			var aaaa=$("<img>");
			aaaa.attr("src","<%=request.getContextPath()%>/images/点赞1.png");
			aaaa.attr("value",1);
			aaaa.addClass("dianzan");
			aaaa.click(dianzana);
			$(".dianzanli").append(aaaa);
			$.ajax({
				url:"/movies/MoviesServlet?",
				type:"get",
				data:{action:"dianzan",movieId:"<%=movie.getId()%>"},
				async:false,
				success:function(mes){
					if(mes=="0"){
						location.href="/movies/denglupage.jsp";
					}
				}
			})
			return false;
		}
		 if(a==1){
			$(".dianzanli").html("");
			$(".dianzanli").html("");
			var bbbb=$("<img>");
			bbbb.attr("src","<%=request.getContextPath()%>/images/点赞.png");
			bbbb.attr("value",0);
			bbbb.addClass("dianzan");
			bbbb.click(dianzana);
			$(".dianzanli").append(bbbb);
			$.ajax({
				url:"/movies/MoviesServlet?",
				type:"get",
				data:{action:"quxiaodianzan",movieId:"<%=movie.getId()%>"},
				async:false,
				success:function(){
					
				}
			})
		}
	}
	
	
	//网页加载结束前添加收藏的方法
	$(function(){
		$(".shoucang").click(shoucang);
	})
	
	//收藏方法
	function shoucang(){
		var a=parseInt($(this).attr("value"));
		if(a==0){
			$(this).attr("value",1);
			$(this).attr("src","<%=request.getContextPath()%>/images/星星4.png");
			$.ajax({
				url:"/movies/MoviesServlet?",
				type:"get",
				data:{action:"shoucang",movieId:"<%=movie.getId()%>"},
				async:false,
				success:function(mes){
					if(mes=="0"){
						location.href="/movies/denglupage.jsp";
					}
				}
			})
			return false;
		}
		 if(a==1){
			$(this).attr("value",0);
			$(this).attr("src","<%=request.getContextPath()%>/images/星星3.png");
			$.ajax({
				url:"/movies/MoviesServlet?",
				type:"get",
				data:{action:"quxiaoshoucang",movieId:"<%=movie.getId()%>"},
				async:false,
				success:function(){
					
				}
			})
		}
	}
	//网页加载结束后给评论他人添加点击事件
	$(function(){
		$(".pingluntaren").click(function(){
			
			var jj=$("<form></form>");
			jj.attr("action","/movies/MoviesServlet?action=pingluntaren");
			jj.attr("method","post");
			jj.addClass("tiJiaoBiaoDanTiJiao");
			$(this).parent().next().append(jj);
			var kk=$("<textarea></textarea>");
			kk.attr("name","pingluntarentext");
			kk.attr("id","pingluntarentext");
			jj.append(kk);
			var ll=$("<input>");
			ll.attr("type","submit");
			ll.addClass("tijiaotarenpinglun");
			jj.append(ll);
			
			var shanChuPingLunDuiHua=$("<input>");
			shanChuPingLunDuiHua.attr("type","button");
			shanChuPingLunDuiHua.addClass("shanChuPingLunDuiHua");
			shanChuPingLunDuiHua.val("关闭");
			jj.append(shanChuPingLunDuiHua);
			
			var beipinglunval=$(this).parent().find(".beipinglun").val();
			var beipinglun=$("<input>");
			beipinglun.attr("type","hidden");
			beipinglun.val(beipinglunval);
			beipinglun.attr("name","reId");
			jj.append(beipinglun);
			var movieId=$(this).parent().parent().parent().parent().parent().find(".movieId").val();
			var beipinglunmovieId=$("<input>");
			beipinglunmovieId.attr("type","hidden");
			beipinglunmovieId.val(movieId);
			beipinglunmovieId.attr("name","movieId");
			jj.append(beipinglunmovieId);
			var edu;
			var tem={initiaFrameWidth:500,initiaFrameHeight:600,autoFloatEnabled:false,autoHeightEnabled:false};
			
			edu=UE.getEditor("pingluntarentext",tem);
			//点击评论他人按钮后添加给评论他人的删除按钮添加方法
			$(".shanChuPingLunDuiHua").click(function(){
				$(".tiJiaoBiaoDanTiJiao").remove();
				
			});
			
		});
	})
	
	
	
	
	
	
	//网页加载结束后给举报添加点击事件
	$(function(){
		$(".jubao").click(function(){
			var pinglunId=$(this).attr("jubao");
			$.ajax({
				url:"/movies/MoviesServlet",
				type:"get",
				data:{action:"jubao",pinglunId:pinglunId},
				async:false,
				success:function(mes){
					if(mes=="0"){
						location.href="/movies/denglupage.jsp";
					}
					else{
						alert("举报成功");
						}
					
				}
			})
		});
	})
</script>

<body class="div">
	<div style="background-color:#FFFFFF;width:1200px;margin: auto; ">
	<div class="listdiv">
		<div class="imgdiv">
			<div class="haibao" style="background-image: url(/movies/images/<%=movie.getMovieImage()%>);"><input class="fenshutext" type="text" value="<%=str%>"></div>
			
		</div>
		<div class="jianjiediv">
			<ul>
				<li><span class="moviename"><%=movie.getMovieName() %></span></span></li>
				<br><br>
				<li>地区：<a href="javascript:void(0);">&nbsp;<%=movie.getMovieCountryId().getCountry() %></a></li>
				<li>语言： <a href="javascript:void(0);"><%=movie.getMovieLanguageId().getLanguageType() %> </a></li>
				<li>类型：<a href="javascript:void(0);"> <%=movie.getMovieTypeId().getMovieType() %> </a> </li>
				<li>导演：<%for(Director director:allDirector){
						%>
							<a href="/movies/MoviesServlet?action=findMovieByDirector&id=<%=director.getId()%>"> <%=director.getDirectorName() %></a>&nbsp;&nbsp;
						<%
				} %>
				</li>
				<li><a  href="javascipt:void(0);"></a>
					演员： <%for(Actor actor:allActor){
						%>
						 <a href="/movies/MoviesServlet?action=findMovieByActor&id=<%=actor.getId()%>"> <%=actor.getActorName() %></a>
						<%
					} %>
				</li>
				<li>
					<%SimpleDateFormat aaa=new SimpleDateFormat("yyyy-MM-dd"); %>
					时长：  <%=movie.getMovieTime() %>分钟
				</li>
				<li>上映时间：<%=aaa.format(movie.getMovieShowtime()) %></li>
			</ul>
				
		</div>
		
		<div class="dafendiv">
			<ul>
				<br><br>
				<li>请打分：</li>
				<br>
				<li class="xingxingli">
				<img class="xingxing" value="1"  src="<%=request.getContextPath()%>/images/星星3.png">
				<img class="xingxing" value="2" src="<%=request.getContextPath()%>/images/星星3.png">
				<img class="xingxing" value="3" src="<%=request.getContextPath()%>/images/星星3.png">
				<img class="xingxing" value="4"  src="<%=request.getContextPath()%>/images/星星3.png">
				<img class="xingxing" value="5"  src="<%=request.getContextPath()%>/images/星星3.png">
				</li>
				<br>
				<li class="dianzanli"><img class="dianzan" value="0"  src="<%=request.getContextPath()%>/images/点赞.png"></li>
				<br>
				<li class="shoucangli" ><span >加入收藏</span><img value="0"  align="center" class="shoucang" src="<%=request.getContextPath()%>/images/星星3.png"></li>
			</ul>
		</div>
		<div style="width:560px;heght:100px;float:left;margin-left:20px;">
			剧情简介：
						&nbsp;&nbsp;&nbsp;&nbsp;
						<%=movie.getMovieIntroduction() %>
						
	</div>
	</div>
	
	<form method="post" action="/movies/MoviesServlet?action=pinglun">
	<div  class="pinlundiv" style="clear:both;margin-top:-20px;">
		<span class="shuru">请输入您的评论：</span>
		<br>
		<textarea name="pinglun" id="pinglun"></textarea>
		<input type="hidden" name="movieId" class="movieId" value="<%=movie.getId() %>">
		<input   class="tijiao" type="submit" value="提交您的评论">
	</div>
	</form>
	<div class="showpinglun" style="background:#FFFFFF;clear:both">
		<span class="shuru">评论</span>
		<br>
		
			<%
			
			
			int a=0;
			int i=0;
			for(Discuss discuss:allDiscuss){
				i++;
				if(discuss.getReId()==0){
				%>
				<ul>
				<li class="pingluntarenli">
					<img class="touxiang"  src="/movies/images/<%=discuss.getUserId().getUserFaceimage()%>">
					<a href="/movies/TaRenServlet?action=userPage&uzi=<%=discuss.getUserId().getId()%>"><%=discuss.getUserId().getUserName() %></a>评论了电影
				</li>
				<li>
				<br>
				&emsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=(discuss.isHidden())?("该评论已屏蔽"):(discuss.getMovieDiscuss())%>
				</li>
				<li>
					<%=aaa.format(discuss.getDiscussTime()) %>
					<input class="beipinglun" type="hidden" value="<%=discuss.getId()%>">
				&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript: void(0);" class="pingluntaren">评论</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0);" jubao="<%=discuss.getId() %>" class="jubao">举报</a>
				</li>
				<hr>
				</ul>
				
				<%
				}
				else{
					%>
					
						<ul>
				<li class="pingluntarenli" >
					<img class="touxiang"  src="/movies/images/<%=discuss.getUserId().getUserFaceimage()%>">
					<a href="/movies/TaRenServlet?action=userPage&uzi=<%=discuss.getUserId().getId()%>"><%=discuss.getUserId().getUserName() %></a>
					
					评论&nbsp;&nbsp;
					<div class="beipinglundiv" style="background-color:#cccccc">
						<a href="/movies/TaRenServlet?action=userPage&uzi=<%=discuss.getReUser().getId()%>"><%=discuss.getReUser().getUserName() %></a>:
						<span class="reDiscuss"><%=(discuss.isRehidden())?("该评论已屏蔽"):(discuss.getReMovieDiscuss()) %></span>
					</div>
					<br>
				</li>
				<li style="padding-left:34px;">
				<%=(discuss.isHidden())?("该评论已屏蔽"):(discuss.getMovieDiscuss())%>
				</li>
				<li>	
					<%=aaa.format(discuss.getDiscussTime())  %>
					<input class="beipinglun" type="hidden" value="<%=discuss.getId()%>">
					&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript: void(0);" class="pingluntaren">评论</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0);"  jubao="<%=discuss.getId() %>" class="jubao">举报</a>
				</li>
				<hr>
				</ul>
				
					<%
				}
			} 
			
			if(i==0){
				%>
					<br>
					您是第一条评论！
				<%
			}
			else{
				%>
				<div  style="width:200px; margin:auto;"><a page="0" class="previouPage" href="javascript:void(0);">上一页</a>&emsp;&emsp;&emsp;<a page="1" class="nextPage" href="javascript:void(0);">下一页</a></div>
				<%
			}
			%>
			
			
	</div>
	</div>
</body>
<script type="text/javascript">
	//网页加载结束后给上一页添加点击事件
	$(function(){
		$(".showpinglun").on("click",".previouPage",function(){
			var page=$(".previouPage").attr("page");
			var a=eval(page-1);
			var movieId=$(".movieId").val();
			if(a<=0){
				alert("已经是第一页了");
				return;
			}
			else{
				$.ajax({
					url:"/movies/MoviesServlet",
					type:"get",
					data:{action:'previouPage',page:a,movieId:movieId},
					success:function(mes){
						$(".showpinglun").html("");
							$(".showpinglun").html(mes);
					}
				})
			}
		});
	})
	
	//网页加载结束后给下一页添加方法
	$(function(){
		$(".showpinglun").on("click",".nextPage",function(){
			var page=$(".nextPage").attr("page");
			var a=eval(page);
			var movieId=$(".movieId").val();
			if(a>=<%=pager.getPagerNum()%>){
				alert("已经是最后一页了");
				return;
			}
			else{
				page++;
				$.ajax({
					url:"/movies/MoviesServlet",
					type:"get",
					data:{action:'nextPage',page:page,movieId:movieId},
					success:function(mes){
						$(".showpinglun").html("");
							$(".showpinglun").html(mes);
					}
				})
			}
		});
	})
</script>
</html>